<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/10/10 20:47
 */

namespace module\ai\library\channel\platform;

use module\ai\library\channel\abstract\Platform;
use mof\Model;

class ZhipuPlatform extends Platform
{
    protected string $regUrl = 'https://www.bigmodel.cn/invite?icode=4a4IZnnGRUKTmcsu6y%2FQ82czbXFgPRGIalpycrEwJ28%3D';

    public static function getName(): string
    {
        return '智谱AI';
    }

    public static function getFlag(): string
    {
        return 'zhipu';
    }


    public static function models(): array
    {
        return [
            'glm-4-plus'   => 'glm-4-plus',
            'glm-4-0520'   => 'glm-4-0520',
            'glm-4-air'    => 'glm-4-air',
            'glm-4-airx'   => 'glm-4-airx',
            'glm-4-long'   => 'glm-4-long',
            'glm-4-flash'  => 'glm-4-flash(免费)',
            'glm-4-flashx' => 'glm-4-flashx',
        ];
    }


    public function getConfigForm(Model $model = null): array
    {
        return [
            ...parent::getConfigForm($model),
            [
                "label" => "temperature",
                "prop"  => "config.temperature",
                "value" => $model['config']['temperature'] ?? '',
                "intro" => "采样温度，控制输出的随机性，必须为正数取值范围是：[0.0, 1.0]，默认值为0.95",
            ],
            [
                "label" => "max_tokens",
                "prop"  => "config.max_tokens",
                "value" => $model['config']['max_tokens'] ?? '',
                "intro" => "模型输出的最大token数，最大输出为4095，默认值为1024",
            ],
            [
                "label" => "top_p",
                "prop"  => "config.top_p",
                "value" => $model['config']['top_p'] ?? '',
                "intro" => "另用温度取样的另一种方法，取值范围是：[0.0, 1.0]，默认值为0.7",
            ],
        ];
    }

    public function getKeyColumns(): array
    {
        return [
            'api_key' => [
                'label'  => 'Api-Key',
                'secret' => true,
            ]
        ];
    }
}